﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyMvcStoreApplication.Models;

namespace MyMvcStoreApplication.Repositories
{
    public class SocialRepository
    {
        MusicStoreEntities musicStoreEntities = new MusicStoreEntities();


        public List<Album> GetAlbumes()
        {
            return musicStoreEntities.Albumes.
                OrderByDescending(al => al.Likes).ThenBy(al => al.Artista.Nombre).ThenBy(al => al.Nombre).
                ToList();
        }

        public List<Album> GetAlbumes(int genero)
        {
            return musicStoreEntities.Albumes.
                   Where(a => a.GeneroId == genero).
                   OrderByDescending(al => al.Likes).ThenBy(al => al.Artista.Nombre).ThenBy(al => al.Nombre).
                   ToList();
        }

        public Album GetAlbum(int id)
        {
            return musicStoreEntities.Albumes.
                Include("Genero").
                Include("Artista").
                First(a => a.ID == id);
        }

        public void Save()
        {
            musicStoreEntities.SaveChanges();
        }

        public List<Genero> GetGeneros()
        {
            return musicStoreEntities.Generos.ToList();
        }
    }
}